package cn.apotato.dynamicdatascore.controller;

import cn.apotato.dynamicdatascore.domain.User;
import cn.apotato.dynamicdatascore.entity.Result;
import cn.apotato.dynamicdatascore.service.UserService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/user")
@RestController
public class UserController {

    private final UserService userService;

    public UserController(UserService userService) {
        this.userService = userService;
    }

    /**
     * 保存用户
     *
     * @param user 用户
     * @return {@link Result }<{@link Boolean }>
     */
    @PostMapping("/save")
    public Result<Boolean> saveUser(@RequestBody User user) {
        return Result.ok(userService.saveOrUpdate(user));
    }

    @GetMapping("/list")
    public Result<List<User>> list() {
        return Result.ok(userService.list());
    }
}
